#!/usr/bin/python2.7
from optparse import OptionParser
from appmain import AppMain
from curen.utils.classloader import load_class
import ConfigParser
import sys
import os
import os.path
import signal

def tofile(filename, text):
    f = file(filename, 'w+')
    f.write(text)
    f.close()
    
if __name__ == '__main__':
    module = sys.argv[1]
    rt = raw_input("create module %s (y or n) y"%module)
    if rt == '' or rt == 'y':
        os.chdir('module')
        os.mkdir(module)
        os.chdir(module)
        tofile('__init__.py', '#coding:utf-8')
        tofile('controller.py', 
'''#coding:utf-8
import model as db
reload(db)

def index(req, *kw):
    req.render('index.mako')
''')
        tofile('model.py', 
'''#coding:utf-8
from proxy.mongo import db
import pymongo
import bson
import time
''')
        os.mkdir('template')
        os.chdir('template')
        tofile('index.mako', '')
        tofile('defs.mako', '')
        tofile('view.mako', '')
        tofile('edit.mako', '')
        tofile('post.mako', '')
        
       